package ali;

/**
 * 无锁实现方案
 * @author wxh
 */
public class Solution_17_2 {

	public volatile static boolean FLAG = true;
	private static int MAX_PRINT = 10;

	public static void main(String[] args) throws InterruptedException {

		Thread threadA = new Thread(() -> {
			int count = 0;
			while (count <= MAX_PRINT) {
				if (FLAG) {
					System.out.print("阿");
					count++;
					FLAG = false;
				}
			}
		});

		Thread threadB = new Thread(() -> {
			int count = 0;
			while (count <= MAX_PRINT) {
				if (!FLAG) {
					System.out.print("里");
					count++;
					FLAG = true;
				}
			}
		});

		threadA.start();
		threadB.start();

		threadA.join();
		threadB.join();

		// 等三个线程执行完，再
		System.out.println("");
		System.out.println("任务完毕");


	}

}